﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Globalization;
using System.IO;

namespace BT_web__nhom06
{
    public partial class Sua_ThongTinHD : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string mahoatdong = Request.QueryString["id"];
                if (mahoatdong != null)
                {
                    DataTable tbl = Tienichsql.ketnoicsdl.ChayLenhSelectDuLieu("SELECT * FROM hoatdongdoan where mahoatdong=@mahoatdong", "@mahoatdong", mahoatdong);
                    if (tbl.Rows.Count > 0)
                    {
                        DataRow dr = tbl.Rows[0];
                        txt_mahoatdong.Text = mahoatdong;
                        txttenhoatdong.Text = (string)dr["tenhoatdong"];
                        txtmota.Text = (string)dr["tenhoatdong"];
                        if (dr.IsNull("tgbatdau") == false)
                            txtthoigianbatdau.Text = ((DateTime)dr["tgbatdau"]).ToString("dd/MM/yyyy");
                        else
                            txtthoigianbatdau.Text = "";
                        if (dr.IsNull("tgketthuc") == false)
                            txtthoigianketthuc.Text = ((DateTime)dr["tgketthuc"]).ToString("dd/MM/yyyy");
                        else
                            txtthoigianketthuc.Text = "";
                        txtdiadiem.Text = (string)dr["diadiem"];
                        txthotennguoiphutrach.Text = (string)dr["hotennguoiphutrach"];
                        txtdienthoai.Text = (string)dr["sodtnguoiphutrach"];
                        dlsttinhtrang.SelectedValue = dr["tinhtrang"].ToString();
                    }
                }
                else
                    Response.Redirect("QL_hoatdongdoan.aspx");
            }
        }

        protected void btnsua_Click(object sender, EventArgs e)
        {
            string mahoatdong = Request.QueryString["id"];
            int ketqua = 0;
            DateTime tgbatdau;
            DateTime tgketthuc;
            if (mahoatdong != null)
            {
                string tenhoatdong = txttenhoatdong.Text;
                string mota = txtmota.Text;
                tgbatdau = DateTime.Parse(txtthoigianbatdau.Text, new CultureInfo("fr-FR"));
                tgketthuc = DateTime.Parse(txtthoigianketthuc.Text, new CultureInfo("fr-FR"));
                string diadiem = txtdiadiem.Text;
                string hotennguoiphutrach = txthotennguoiphutrach.Text;
                string sodtnguoiphutrach = txtdienthoai.Text;
                string tinhtrang = dlsttinhtrang.SelectedValue.ToString();
                string lenhsql = "update hoatdongdoan set [tenhoatdong]=@tenhoatdong,[mota]=@mota, [tgbatdau]=@tgbatdau,[tgketthuc]=@tgketthuc, [diadiem]=@diadiem, [hotennguoiphutrach]=@hotennguoiphutrach,[sodtnguoiphutrach]=@sodtnguoiphutrach,[tinhtrang]=@tinhtrang where [mahoatdong] = @mahoatdong";
                ketqua = Tienichsql.ketnoicsdl.chaylenhcapnhatdulieu(lenhsql, new string[] { "@tenhoatdong", "@mota", "@tgbatdau", "@tgketthuc", "@diadiem", "@hotennguoiphutrach", "@sodtnguoiphutrach", "@tinhtrang", "@mahoatdong" }, new object[] {tenhoatdong,mota,tgbatdau,tgketthuc,diadiem,hotennguoiphutrach,sodtnguoiphutrach,tinhtrang,mahoatdong });
                if (ketqua == 1)
                    Label1.Text = "cap nhat thanh cong!";
                else
                    Label1.Text = "cap nhat khong thanh cong!";
            }
        }

        protected void btnthoat_Click(object sender, EventArgs e)
        {
            Response.Redirect("QL_hoatdongdoan.aspx");
        }

      

       
    }
}